<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>数组去重。</title>  
</head>

<body>
<script>
//一、ES6
//[1, "true", true, 15, false, undefined, null, NaN, "NaN", 0, "a", {}, {}]
function unique4set (arr) {
  return Array.from(new Set(arr))
}
var arr4set = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique4set(arr4set))

//二、双层for循环
//[1, "true", 15, false, undefined, NaN, NaN, "NaN", "a", {…}, {…}]     //NaN和{}没有去重，两个null直接消失了
function unique4for(arr){            
        for(var i=0; i<arr.length; i++){
            for(var j=i+1; j<arr.length; j++){
                if(arr[i]==arr[j]){         //第一个等同于第二个，splice方法删除第二个
                    arr.splice(j,1);
                    j--;
                }
            }
        }
return arr;
}
var arr4for = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique4for(arr4for))

//下面是测试

</script>
</body>
</html>
                                